<?php
/**
 * URL调度类
 * 
 * @file Router.class.php
 * @create 2012-08-03
 * @version v1.0
 * @author veapon 
 * @copyright (C) veapon.com
 */
if( !defined('__ROOT__') ) die('Access Denied');
class Router{

	/**
	 * 解释URL
	 * 
	 * @return 
	 * @since v1.0
	 * @create 2012-08-03
	 */
	public static function init(){
		$queryString = "";
		$url = array();
		if( false!== strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) ){
			$queryString = str_replace($_SERVER['SCRIPT_NAME'],"",$_SERVER['REQUEST_URI']);
			$queryString = substr($queryString,1);
		}
		$url = explode('/',$queryString);
		$module = $url[0] ? $url[0] : DEFAULT_MODULE;
		$controller = $url[1] ? $url[1] : DEFAULT_CONTROLLER;
		$action = $url[2] ? $url[2] : DEFAULT_ACTION;
		define('MODULE', $module);
		define('CONTROLLER', $controller);
		define('ACTION', $action);
		$_GET['MODULE'] = $module;
		$_GET['CONTROLLER'] = $controller;
		$_GET['ACTION'] = $action;
		if( isset($url[3]) ){
			for($i=3; $i<count($url); $i=$i+2){
				$_GET[$url[$i]] = $url[$i+1];
			}
		}
		return;
	}
}
